function throlle(func, timeout) {
    let timer = null, preview = 0, that = this
    return function (...args) {
        let now = +new Date()
        let diff = now - preview
        if (diff >= timeout) {
            clearTimeout(timer);
            timer = null;
            func.call(that, ...args)
            preview = now
        } else if (timer) {
            timer = setTimeout(() => {
                clearTimeout(timer);
                timer = null;
                previous = +new Date();
                func.call(that, ...args)
            }, timeout)
        }
    }
}
// fnColorSet({r: 255, g: 0, b: 0})
function fnColorSet(color) {
    aColorMainStore = [];

    var oLeftColor = { r: 255, g: 255, b: 255 };
    var oRightColor = JSON.parse(JSON.stringify(color));
    var oBottomColor = { r: 0, g: 0, b: 0 };
    var oMainColor = { r: 255, g: 255, b: 255 };

    var oYStep = {
        lStep: Math.floor(256 / nMainH),
        lRemainder: 256 / nMainH - Math.floor(256 / nMainH),
        lAdd: 0
    }

    for (let k in oRightColor) {
        oYStep[k + 'Step'] = Math.floor((oRightColor[k] - oBottomColor[k] + 1) / nMainH);
        oYStep[k + 'Remainder'] = (oRightColor[k] - oBottomColor[k] + 1) / nMainH - Math.floor((oRightColor[k] - oBottomColor[k] + 1) / nMainH);
        oYStep[k + 'Add'] = 0;
    }

    let oXStep = {}
    for (let k in oLeftColor) {
        oXStep[k + 'Step'] = Math.floor((oLeftColor[k] - oRightColor[k]) / nMainW)
        oXStep[k + 'Remainder'] = (oLeftColor[k] - oRightColor[k]) / nMainW - Math.floor((oLeftColor[k] - oRightColor[k]) / nMainW)
        oXStep[k + 'Add'] = 0;
    }

    for (let i = 0; i < nMainH; i++) {
        if (i > 0) {
            oYStep.lAdd += oYStep.lRemainder;
            for (let k in oLeftColor) {
                if (oYStep.lAdd > 1) {
                    oLeftColor[k] = oLeftColor[k] - (oYStep.lStep + 1)
                } else {
                    oLeftColor[k] = oLeftColor[k] - oYStep.lStep
                }
                oYStep[k + 'Add'] += oYStep[k + 'Remainder'];
                if (oYStep[k + 'Add'] > 1) {
                    oRightColor[k] = oRightColor[k] - (oYStep[k + 'Step'] + 1)
                    oYStep[k + 'Add'] = oYStep[k + 'Add'] - 1
                } else {
                    oRightColor[k] = oRightColor[k] - oYStep[k + 'Step']
                }
            }
            if (oYStep.lAdd > 1) {
                oYStep.lAdd = oYStep.lAdd - 1
            }
        }
        aColorMainStore.push([]);
        oMainColor = JSON.parse(JSON.stringify(oLeftColor))

        for (let j = 0; j < nMainW; j++) {
            if (j != 0 && j != nMainW - 1) {
                for (let k in oMainColor) {
                    oXStep[k + 'Add'] += oXStep[k + 'Remainder']
                    if (oXStep[k + 'Add'] > 1) {
                        oMainColor[k] = oMainColor[k] - (oXStep[k + 'Step'] + 1);
                        oXStep[k + 'Add'] = oXStep[k + 'Add'] - 1
                    } else {
                        oMainColor[k] = oMainColor[k] - oXStep[k + 'Step'];
                    }
                }
            }
            if (j == nMainW - 1) {
                oMainColor = JSON.parse(JSON.stringify(oRightColor));
            }

            aColorMainStore[i].push(JSON.stringify(oMainColor))
        }
    }
}

function fnColorFull(color) {
    var color = JSON.parse(color);
    eColorFull.style.background = `rgb(${color.join(',')})`;
    for (let i = 0; i < aColorInput.length; i++) {
        aColorInput[i].value = color[i]
    }
}

